#include <iostream>
#include <dll_mattool.h>
#include <fstream>

int main() {
	int width, height, imageSize;
	//double width1 = 80.0, depth1 = 0.0, depth2 = 40.0, widthjingpian = 1.5, ff1 = 40.0, jianju = 0.1;
	double width1 = 80.0, depth1 = 0.0, depth2 = 40.0, widthjingpian = 1.5;
	double ff1 = 40.0, jianju = 0.1, jianju_1 = 0.1;
	int beamLength = getBeamLength("../dll_mattool/FMCExport20250218043443beamLength2096_withBeamIndex_codedExcitation_barker_double.csv");

	jianju = 80.0 / 480.0;
	jianju_1 = 40.0 / (beamLength - 16.0);

	getImageSize(width1, depth1, depth2, jianju, jianju_1, &width, &height, &imageSize);

	double* img = new double[width * height];
	//tool_process("../dll_mattool/moliang.csv", "../dll_mattool/sanjiang_7_0.5.capture_fmc.csv", (char*)img, 80.0, 0.0, 40.0, 1.5, 100, 0.1);
	tool_process("../dll_mattool/moliang.csv", "../dll_mattool/FMCExport20250218043443beamLength2096_withBeamIndex_codedExcitation_barker_double.csv",
		(char*)img, width1, depth1, depth2, widthjingpian, ff1, jianju, jianju_1);
	//memset(img, 0, sizeof(double) * width * height);

	std::ofstream ofs("final_image.csv", std::ios::out);
	if (ofs.is_open()) {
		for (int irow = 0; irow < height; irow++) {
			for (int icol = 0; icol < width; icol++) {
				ofs << img[icol * height + irow] << ",";
			}
			ofs << '\n';
		}
		ofs.close();
	}
	else {
		std::cout << "failed to build file: " << "final_image_test.csv" << std::endl;
	}

	double* resizeImg = new double[480 * beamLength];
	resizeImage(img, height, width, 480, beamLength, resizeImg);

	std::ofstream of("resized_image.csv", std::ios::out);
	if (of.is_open()) {
		std::cout << "gona saving... " << beamLength << std::endl;
		for (int irow = 0; irow < 480; irow++) {
			for (int icol = 0; icol < beamLength; icol++) {
				of << resizeImg[icol * 480 + irow] << ",";
			}
			of << '\n';
		}
		of.close();
	}
	else {
		std::cout << "failed to build file: " << "resized_image.csv" << std::endl;
	}

	delete[] resizeImg;
	delete[] img;
	return 0;
}